import { useEffect, useState, useRef } from 'react';

export default () => {
    const [rsz, setRsz] = useState({});
    const Tmr = useRef(null);
    useEffect(() => {
        const dm = document.documentElement || document.body;

        const rs = () => {
            clearTimeout(Tmr.current);
            Tmr.current = setTimeout(() => {
                setRsz({
                    sch: dm.clientHeight,
                    scw: dm.clientWidth,
                    w: dm.scrollWidth,
                    h: dm.scrollHeight
                });
            }, 100)
        }

        window.addEventListener('resize', rs);

        // init
        rs();

        return () => {
            window.removeEventListener('resize', rs);
        }
    }, []);

    return rsz;
}